package com.koron.common.core.business.print.printstandard;

import com.koron.common.core.business.print.ReportServiceInterface;
import com.koron.common.core.business.print.bean.PrintTemplateBean;
import com.koron.common.core.config.ThreadLocalContext;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ReportServiceStandardImpl implements ReportServiceInterface {

    private static PrintStandardService printstdService;

    private PrintTemplateBean printTemplate;
    private String mark = "print";

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }


    public ReportServiceStandardImpl() {
    }

    @Autowired
    public ReportServiceStandardImpl(PrintStandardService printstdService) {
        ReportServiceStandardImpl.printstdService = printstdService;
    }

    public ReportServiceStandardImpl(PrintTemplateBean printTemplate) {
        super();
//        this.printstdService = new PrintStandardService();
        this.printTemplate = printTemplate;
        this.mark = "print";
    }

    public PrintStandardService getPrintstdService() {
        return printstdService;
    }

    public void setPrintstdService(PrintStandardService printstdService) {
        this.printstdService = printstdService;
    }

    @Override
    public PrintTemplateBean getPrintTemplate() {
        return printTemplate;
    }

    public void setPrintTemplate(PrintTemplateBean printTemplate) {
        this.printTemplate = printTemplate;
    }

    @Override
    public String getField() {
        String currDs = printTemplate.getEamuser().getCurrDs();
        return ADOConnection.runTask(currDs, printstdService, "getFields", String.class, printTemplate.getId());
    }

    @Override
    public List<PrintTemplateBean> getTemplateListByBusiness() {
        String currDs = printTemplate.getEamuser().getCurrDs();
        return ADOConnection.runTask(currDs, printstdService, "getTemplateListByBusiness", List.class, printTemplate.getBusinessId());
    }

    @Override
    public PrintTemplateBean getTemplateListById() {
        String currDs = printTemplate.getEamuser().getCurrDs();
        return ADOConnection.runTask(currDs, printstdService, "getTemplateListById", PrintTemplateBean.class, printTemplate.getId());
    }

    @Override
    public int insertInitTemplate() {
        String currDs = printTemplate.getEamuser().getCurrDs();
        return ADOConnection.runTask(currDs, printstdService, "createInitTemplate", Integer.class, printTemplate);
    }

    @Override
    public int updateTemplateContent() {
        String currDs = printTemplate.getEamuser().getCurrDs();
        return ADOConnection.runTask(currDs, printstdService, "updateTemplateContent", Integer.class, printTemplate.getId(), printTemplate.getContent());
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }
}
